import api from '../../utils/api';

Page({

  data: {
    newsList: []
  },

  onLoad: function (options) {
    this.getLikeNewsList();
  },
  
  getLikeNewsList() {
    const _this = this;
    wx.showLoading({
      title: '请稍后...'
    });
    api({
      url: '/User/queryLikeNewsList',
      method: 'GET',
      success: function (res) {
        wx.hideLoading();
        _this.setData({
          newsList: res.data.data
        });
      }
    });
  },

  toLike(e) {
    const { item } = e.currentTarget.dataset;
    const _this = this;
    wx.showLoading({
      title: '请稍后...'
    });
    api({
      url: '/User/likeNews',
      method: 'POST',
      data: {
        id: item.id
      },
      success: function (res) {
        wx.hideLoading();
        _this.getLikeNewsList();
        if(item.isLike !== 0) {
          wx.showToast({
            title: '取消成功',
            icon: 'success',
            duration: 1000,
            mask: false,
          });
        }
      }
    });
  }
})